import request from "../utils/request";

export default {
    // 区分命名
    namespace: "home",
    // 定义数据
    state: [],
    // 同步修改数据
    reducers: {
        change(state, action) {
            state += 1
            return state
        },
        setList(state, { res }) {
            state = res
            return state
        }
    },
    // 异步修改数据
    effects: {
        *homeAsync(action, { call, put }) {
            let res = yield request("/api/getList")
            res = res.data.data
            yield put({ type: "setList", res })
        },
    },
    subscriptions: {
        init({ dispatch }) {
            dispatch({ type: "homeAsync" })
        }
    }
}
